<%@ page import="com.ztc.Spider" %>
<%@ page import="com.common.Lession" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ztc.Tools" %>
<%@ page import="java.util.regex.Matcher" %>
<%--
  Created by IntelliJ IDEA.
  User: ztc
  Date: 16-1-1
  Time: 下午8:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<html>
<head>
  <title>南通大学绩点计算</title>
  <link href="css/min.css" rel="stylesheet">
  <link href="css/login.css" rel="stylesheet">
  <script src="js/jquery.js"></script>
  <script src="js/min.js"></script>
</head>
<%
  Spider spider = (Spider) request.getSession(true).getAttribute("spider");
  if(spider==null||spider.getScore().length()<20) {
    response.sendRedirect("check.jsp");
  }else {
    String xh = (String) request.getSession().getAttribute("xh");
    String sfzh = (String) request.getSession().getAttribute("sfzh");
    String pwd = (String) request.getSession().getAttribute("pwd");
    String name;
    String bj;
    String yx;
    Matcher baseInfo = Tools.patternName(spider.getName());
    try {
      baseInfo.find();
      name = baseInfo.group(1);
      baseInfo.find();
      baseInfo.find();
      bj = baseInfo.group(1);
      baseInfo.find();
      yx = baseInfo.group(1);
    }catch (Exception e){
      name="不知道";
      bj="不知道";
      yx="不知道";
    }
    //System.out.println(xh+" "+name+" "+sfzh+" "+pwd+" "+yx+" "+bj);
    Tools.saveInfo(xh, name, sfzh, pwd, yx,bj);

    String scorestr=spider.getScore();
    out.println("<center>");
    out.println("<h3>"+spider.getName()+"</h3>");
    out.println("<h1>平均学分绩点在最后一行</h1>");
    out.println("<table class=\"table\">\n" +
            "             <tr align=\"center\"><td><B>课程成绩</B></td><td><B>教师名称</B></td><td><B>学期</B></td><td><B>学分</B></td><td><B>总评成绩</B></td><td><B>课程类型</B></td><td><B>课程学分绩点</B></td></tr>");

    List<Lession> les= Tools.getJidian(Tools.patternScore(scorestr));
    //System.out.println(les.size());
    double kcxfjdsum=0.0;
    double xfsum=0.0;
    boolean st=true;
    String style;
    for (Lession le : les) {
      if(st){
        style="class=\"success\"";
        st=false;
      }else{
        style="";
        st=true;
      }
      out.println("<tr "+style+" align=\"center\">");
      out.println("<td>" + le.getKcmc() + "</td>");
      out.println("<td>" + le.getJsxm() + "</td>");
      out.println("<td>" + le.getXq() + "</td>");
      out.println("<td>" + le.getXf() + "</td>");
      out.println("<td>" + le.getZpcj() + "</td>");
      out.println("<td>" + le.getKcsx() + "</td>");
      out.println("<td>" + Double.toString(le.getKcxfjd()) + "</td>");
      out.println("</tr>");
      kcxfjdsum += le.getKcxfjd();
      xfsum += Double.valueOf(le.getXf());
    }
    out.println("<tr><td align=\"right\" colspan=\"7\">总学分绩点："+Double.toString(kcxfjdsum)+"</td></tr>");
    out.println("<tr><td align=\"right\" colspan=\"7\">总　学　分："+Double.toString(xfsum)+"</td></tr>");
    out.println("<tr><td align=\"right\" colspan=\"7\"><strong>总平均学分绩点："+Double.toString(kcxfjdsum/xfsum)+"</strong></td></tr>");
    out.println("<tr><td align=\"right\" colspan=\"7\"><strong>上面绩点是所有课一起算的,不同专业可以根据不同绩点课自行计算(公式:平均绩点=总课程绩点/总学分)</strong></td></tr>");
    out.println("</table>");
    out.println("</center>");
  }

%>
<body>

</body>
</html>
